'''
Created on 22.5.2012

@author: mphkh
'''
from CashFlowUtils.IceBonds import *
from Calendar.Iceland import *
from datetime import date
from datetime import timedelta

tradedate = date(2012,6,1)
valuedate1 = date(2012,7,1)
valuedate2 = date(2012,8,1)
valuedate3 = date(2012,9,1)


#bond = HFF150224()
bond = RIKB190226()
#RB22 = RIKB221026()

buyyield = 0.0247369
mtmyield = 0.069

nominal = 2100000000

cf1 = bond.remaining_cashflows(tradedate)

for obj in cf1:
    print obj.yearfrac, obj.cfdate, obj.daysPeriod, obj.amount, obj.notional, obj.interests, obj.amortization


MarketAmount = 1000000
NomAmount = 1000000/bond.dirtyprice(tradedate, mtmyield)*100

MarketJuly = NomAmount*bond.dirtyprice(valuedate1, mtmyield)/100.0
MarketAug = NomAmount*bond.dirtyprice(valuedate2, mtmyield)/100.0
MarketSept = NomAmount*bond.dirtyprice(valuedate3, mtmyield)/100.0
div = bond.dirtyprice(date(2012,8,14), 0.01)-bond.dirtyprice(date(2012,8,15), 0.01)
print div
print MarketJuly
print MarketAug
print MarketSept+div/100*NomAmount

dev = 0.0050

MarketJuly = NomAmount*bond.dirtyprice(valuedate1, mtmyield+dev)/100.0
MarketAug = NomAmount*bond.dirtyprice(valuedate2, mtmyield+dev)/100.0
MarketSept = NomAmount*bond.dirtyprice(valuedate3, mtmyield+dev)/100.0
div = bond.dirtyprice(date(2012,8,14), 0.01)-bond.dirtyprice(date(2012,8,15), 0.01)
print MarketJuly
print MarketAug
print MarketSept+div/100*NomAmount






'''
print bond.dirtyprice(tradedate, buyyield)
print bond.dirtyprice(valuedate1, mtmyield)
print bond.dirtyprice(valuedate2, mtmyield)

print nominal*bond.dirtyprice(tradedate, buyyield)/100.0
print nominal*bond.dirtyprice(valuedate1, mtmyield)/100.0
print nominal*bond.dirtyprice(valuedate2, mtmyield)/100.0
print bond.duration(tradedate, buyyield)
print bond.duration(valuedate1, mtmyield)
print bond.duration(valuedate2, mtmyield)


yld19 = 0.065
yld22 = 0.07

market0103 = nominal*bond.dirtyprice(valuedate1, mtmyield)/100.0

nom19 = market0103/RB19.dirtyprice(valuedate1, yld19)
nom22 = market0103/RB22.dirtyprice(valuedate1, yld22)

print nom19*RB19.dirtyprice(valuedate1, yld19)
print nom19*RB19.dirtyprice(valuedate2, yld19)

print nom22*RB22.dirtyprice(valuedate1, yld22)
print nom22*RB22.dirtyprice(valuedate2, yld22)
'''

#print RB19.dirtyprice(valuedate1, yld19)
#print RB19.dirtyprice(valuedate2, yld19)


#print RB19.dirtyprice(valuedate1, yld19)
#print RB19.dirtyprice(valuedate2, yld19)

#print RB22.dirtyprice(valuedate1, yld22)
#print RB229.dirtyprice(valuedate2, yld22)




#print 'bond',bond1.duration(ddate, b1yld)

#clean1 = bond1.cleanprice(ddate, b1yld)
#clean2 = bond2.cleanprice(ddate, b2yld)
#clean3 = bond3.cleanprice(ddate, b3yld)

#bonddirty = bond1.dirtyprice(ddate, b1yld)
#rb19dirty = bond2.dirtyprice(ddate, b2yld)
#rb25dirty = bond3.dirtyprice(ddate, b3yld)



#cf1 = bond3.remaining_cashflows(ddate1)

#for obj in cf1:
#    print obj.yearfrac, obj.cfdate, obj.daysPeriod, obj.amount, obj.notional, obj.interests, obj.amortization
    
#for obj in cf2:
#    print obj.yearfrac, obj.cfdate, obj.daysPeriod, obj.amount, obj.notional, obj.interests, obj.amortization